pp108 : Conversion Methods

Conversion Methods

Need for Conversion Methods


The conversion methods that can be defined for globalization component needs to be different from the conventional methods in the sense that the data as well as conversion factors are extensible at run time. A unique method written to handle this case will not be possible, since it depends on various attributes like conversion base, factor of conversion etc. This becomes complex particularly if the conversion is to be extended for more number of data (For example, 100 or more).

To solve this problem, a generic algorithm is written in the component which can convert the data from one form to another form without extending the basic definition.

Currency Conversion Methods


The currency data can be reached through the property currency of the globalization component. To convert the currency in one format to other format, the syntax defined will be as follows:

Scripting

nConvertedUnit = globalID.currency.convertCurrency(sSourceName, sTargetName, nUnits)


Parameters

Parameter

Description

sSourceName

Required. String that denotes the source unit name.

sTargetName

Required. String that denotes the target unit name to convert to.

nUnits

Required. Integer that denotes the number of units to convert.


Return Value


Returns an integer that denotes the source unit (nUnits) converted to target unit.

Example


The sample below will convert the Indian currency to Dutch currency.

var output = globalID.currency.convertCurrency("INR", "NLG", 100)


In the above example, the output returned would be 2000, since the equivalent of Indian money in Dutch currency is 20.

Other Conversion Methods


The convention for calling other conversion methods is defined as follows:

Scripting

nConvertedUnit = globalID.sUnitType.convertsSourceUnitTosTargetUnits(nUnits)


Parameters

Parameter

Description

sUnitType

Required. String that denotes the source unit type to convert to. This can be distance, weight, volume or any defined unit of measurement.

sSourceUnit

Required. String that denotes the source unit to convert to. This unit should be defined in the corresponding unit type.

sTargetUnit

Required. String that denotes the target unit to which the source unit is to be converted.

nUnits

Required. Integer that denotes the units to convert.


Return Value


Returns an integer that denotes the source unit (nUnits) converted to target unit of the given unitType.

Example


The sample below converts the weight in kilograms to tonnes.

var output = globalID.weight.convertkgTotonne(10)


The output returned would be 0.01 in this case, as the equivalent of kg in tonnes is 0.001. The following sample converts the temperature in Celsius to Fahrenheit.

var output = global.temperature.convertcelsiusTofahrenheit(36.5)


The output in this case would be 97.7.

See Also


globalization